// pages/content-list/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    messageList:[],
    loadingMoreHidden: true,
    CurrentPage:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  tapBanner: function (e) {
    var id = e.currentTarget.dataset.id
    var name = e.currentTarget.dataset.name
    var linktype = e.currentTarget.dataset.linktype
    var url = e.currentTarget.dataset.url
    var mobile = e.currentTarget.dataset.mobile
    if (id != 0) {
      if (linktype == "product") {//产品详情
        wx.navigateTo({
          url: "/pages/goods-details/index?id=" + id,
        })
      }
      else if (linktype == "store_class") {//产品分类
        wx.navigateTo({
          url: "/pages/classesTwo/index?id=" + id + "&&name=" + name,
        })
      }
      else if (linktype == "news") {//新闻详情
        wx.navigateTo({
          url: '/pages/news-details/index?newsid=' + id,
        })
      }
      else if (linktype == "news_type") {//新闻列表
        wx.navigateTo({
          url: '/pages/news-list/index?newstypeid=' + id,
        })
      }
      else if (linktype == "page" && id == 1) {//优惠劵
        wx.navigateTo({
          url: url
        })
      }
      else if (linktype == "page" && id == 2) {//关于
        wx.setStorageSync("tap", 0);
        wx.reLaunch({
          url: url
        })
      }
      else if (linktype == "page" && id == 3) {//在线客服
        wx.navigateTo({
          url: url
        })
      }
      else if (linktype == "page" && id == 4) {//申请分销
        wx.navigateTo({
          url: url
        })
      }
      else if (linktype == "page" && id == 5) {//预约留言
        wx.navigateTo({
          url: url
        })
      }
      else if (linktype == "page" && id == 6) {//联系方式
        wx.setStorageSync("tap", 1);
        wx.reLaunch({
          url: url
        })
      }
      else if (linktype == "page" && id == 7) {//一键导航
        wx.setStorageSync("tap", 2);
        wx.reLaunch({
          url: url
        })
      }
      else if (linktype == "page" && id == 8) {//拼团
        wx.navigateTo({
          url: url
        })
      }
      else if (linktype == "page" && id == 9) {//限时秒杀
        wx.navigateTo({
          url: url
        })
      }
    }
    else if (id == 0 && linktype == "h5page") {//h5网页
      wx.navigateTo({
        url: '/pages/h5page/index?url=' + url,
      })
    }
    else if (id == 0 && linktype == "phonecall") {//一键拨号
      wx.makePhoneCall({
        phoneNumber: !isNaN(mobile) ? mobile : name
      })
    }
  },
  tosubmitInfo:function(){
    wx.navigateTo({
      url: '/pages/submitInfo/index',
    })
  },

   //创意设计列表
  getMessageList:function(){
    var that = this 
    wx.request({
      url: app.globalData.host + "/api/Message/GetMessageList?storeId=" +app.globalData.storeId + "&pageNumber=" + that.data.CurrentPage + "&pageSize=6",
      success: function(res) {
        if(res.data.Code == 0){
          var newMsgList = []
          var msgList = res.data.Data.MessageList
          for (var i = 0; i < msgList.length;i++){ 
            var h = msgList[i]
            var str = msgList[i].LinkValue
            h.newImgs =  msgList[i].MsgImg.split(',')
            if (str){
              h.newLinkValue = JSON.parse(str)
            }else{
              h.newLinkValue = []
            }
            newMsgList.push(h)
          }
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.messageList
            newMsgList = preGoods.concat(newMsgList);
          }
          that.setData({
            messageList: newMsgList,
            loadingMoreHidden: res.data.Data.PageModel.HasNextPage
          })
          if (res.data.Data.Title){
            wx.setNavigationBarTitle({
              title: res.data.Data.Title
            })
          }
        }
      },
    })
  },
  loadMore: function (e) {
    var that = this;
    if (!that.data.loadingMoreHidden) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.getMessageList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMessageList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})